package com.dmzc.stage3.AtomicXXX;

import java.util.concurrent.atomic.AtomicIntegerArray;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray;

public class Test2 {
    public static void main(String[] args) {
        AtomicIntegerFieldUpdater<TestMe> updater = AtomicIntegerFieldUpdater.newUpdater(TestMe.class, "i");
        TestMe me = new TestMe();
        for (int i = 0; i < 20; i++) {
            new Thread() {
                @Override
                public void run() {
                    final int MAX = 20;
                    for (int i = 0; i < 20; i++) {
                        System.out.println(updater.getAndIncrement(me));
                    }
                }
            }.start();

        }
    }

    static class TestMe {
        volatile int i;
    }
}
